package com.zzb.projectfactory.framework.role.dao.mybatis;

import com.zzb.projectfactory.framework.role.entity.SysMenu;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 菜单mapper
 * Created by zhangzhenbin on 17-2-28.
 */
@Mapper
public interface SysMenuMapper {
    @Results(id = "SysMenu", value = {
            @Result(property = "id", column = "id", id = true),
            @Result(property = "menuName", column = "menu_name"),
            @Result(property = "menuCode", column = "menu_code"),
            @Result(property = "menuComment", column = "menu_comment"),
            @Result(property = "menuIcon", column = "menu_icon"),
            @Result(property = "menuUrl", column = "menu_url"),
            @Result(property = "menuOrder", column = "menu_order"),
            @Result(property = "menuParentId", column = "menu_parent_id"),
            @Result(property = "menuLevel", column = "menu_level"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time"),
            @Result(property = "creator", column = "creator"),
            @Result(property = "updater", column = "updater"),
            @Result(property = "activate", column = "activate"),
    })
    @Select("select sys_menu.* from sys_menu " +
            "inner join sys_role_menu on sys_role_menu.menu_id = sys_menu.id " +
            "inner join sys_role_user on sys_role_user.role_id = sys_role_menu.role_id " +
            "where sys_role_user.user_id = #{userId} " +
            "and sys_menu.activate = true " +
            "order by sys_menu.menu_level asc , sys_menu.menu_order asc ")
    List<SysMenu> listByUserId(@Param("userId") String userId);

    @Select("select sys_menu.* from sys_menu " +
            "inner join sys_role_menu on sys_role_menu.menu_id = sys_menu.id " +
            "where sys_role_menu.role_id = #{roleId} " +
            "and sys_menu.activate = true " +
            "order by sys_menu.menu_level asc , sys_menu.menu_order asc ")
    @ResultMap("SysMenu")
    List<SysMenu> listByRoleId(@Param("roleId") String roleId);
}
